package com.sc.nft.admin.controller;

import cn.hutool.core.bean.BeanUtil;
import com.sc.nft.admin.request.TempRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.TempCityServerCentre;
import com.sc.nft.entity.vo.TempCityServerCentreVO;
import com.sc.nft.entity.vo.TempWorkRoomVO;
import com.sc.nft.enums.ApplicationRequirementUpOrDownEnum;
import com.sc.nft.service.TempCityServerCentreService;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author 朱梦晨
 * @Description: 城市服务中心/社区网点导出
 * @date 2024-07-25
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/temp/cityServerCentre")
@Api(tags="城市服务中心/社区网点导出模块")
public class TempCityServerCentreController {


    private final TempCityServerCentreService tempCityServerCentreService;

    @PostMapping(value = "/workRoomExport", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "社区网点导出", notes = "社区网点导出", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result tempWorkRoomExcel(){
        return Result.success(tempCityServerCentreService.saveTempCityServerCentreOrWorkRoom(ApplicationRequirementUpOrDownEnum.USER_WORK_ROOM.getCode()));
    }


    @PostMapping(value = "/cityServerCentreExport", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "城市服务中心导出", notes = "城市服务中心导出", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result tempCityServerCentreExcel(){
        return Result.success(tempCityServerCentreService.saveTempCityServerCentreOrWorkRoom(ApplicationRequirementUpOrDownEnum.CITY.getCode()));
    }


    @PostMapping(value = "/download", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "城市服务中心导出下载", notes = "城市服务中心导出下载", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<TempCityServerCentreVO>> findTempCityServerCentreList(@Valid @RequestBody TempRequest request){
        List<TempCityServerCentre> tempCityServerCentreList = tempCityServerCentreService.findTempCityServerCentreList(request.getExportRecordsId());
        List<TempCityServerCentreVO> cityServerCentreExportVOList = BeanUtil.copyToList(tempCityServerCentreList, TempCityServerCentreVO.class);
        return Result.success(cityServerCentreExportVOList);
    }


    @PostMapping(value = "/workRoom/download", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "社区网点导出下载", notes = "社区网点导出下载", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<TempWorkRoomVO>> findWorkRoomList(@Valid @RequestBody TempRequest request){
        List<TempCityServerCentre> tempCityServerCentreList = tempCityServerCentreService.findTempCityServerCentreList(request.getExportRecordsId());
        List<TempWorkRoomVO> workRoomExportVOList = BeanUtil.copyToList(tempCityServerCentreList, TempWorkRoomVO.class);
        return Result.success(workRoomExportVOList);
    }

}
